package org.example.controller.authorization.user;

import com.bianmaba.commons.bean.result.QueryResult;
import com.bianmaba.commons.data.jpa.domain.request.PageableCondition;
import com.bianmaba.commons.data.jpa.domain.request.PageableRequest;
import com.bianmaba.spring.mvc.annotation.RequestResponseBodyConfig;
import com.bianmaba.spring.mvc.config.annotation.EntityParam;
import com.bianmaba.spring.web.controller.CrudController;
import org.example.bean.entity.authorization.User;
import org.example.service.authorization.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;

@RestController
@RequestMapping(value = {"management/authorization/user"})
public class MGTUserController extends CrudController<User, String> {
    @Autowired
    private IUserService service;

    @Override
    protected IUserService getService() {
        return service;
    }

    @RequestResponseBodyConfig
    public QueryResult<List<User>> query(@RequestBody PageableCondition condition) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return super.query(condition);
    }

    @RequestResponseBodyConfig
    @Override
    public QueryResult<List<User>> query(@EntityParam LinkedHashMap<String, Object> params, @EntityParam PageableRequest pageable) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return super.query(params, pageable);
    }
}
